﻿Public Class ctrChinhSuaNV

    Private Sub ctrChinhSuaNV_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        gvNhanVien_Load()
        cmbBangCap_Load()
        cmbChucVu_Load()
        rdNu.Checked = True
        txtHoTen.Select()
    End Sub

    Private Sub gvNhanVien_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        gvNhanVien.DataSource = bus.GetTable()
    End Sub

    Private Sub cmbBangCap_Load()
        Dim bus As BangCapBUS = New BangCapBUS()
        cmbBangCap.DataSource = bus.GetTable()
        cmbBangCap.DisplayMember = "TenBC"
        cmbBangCap.ValueMember = "MaBC"
    End Sub

    Private Sub cmbChucVu_Load()
        Dim bus As ChucVuBUS = New ChucVuBUS()
        cmbChucVu.DataSource = bus.GetTable()
        cmbChucVu.DisplayMember = "TenCV"
        cmbChucVu.ValueMember = "MaCV"
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        frmMain.TabControl1.TabPages.Remove(frmMain.TabControl1.SelectedTab)
    End Sub

    Private Sub btnChinhSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChinhSua.Click
        Dim tmp As NhanVienDTO = New NhanVienDTO()
        tmp.HoTen = txtHoTen.Text
        tmp.CMND = txtCMND.Text
        If rdNu.Checked = True Then tmp.GioiTinh = True Else tmp.GioiTinh = False
        tmp.NgaySinh = dtNgaySinh.Value
        tmp.DiaChi = txtDiaChi.Text
        tmp.DienThoai = txtDienThoai.Text
        tmp.MaBC = cmbBangCap.SelectedValue
        tmp.MaCV = cmbChucVu.SelectedValue
        tmp.TinhTrang = True
        tmp.MaNV = gvNhanVien.CurrentRow.Cells(0).Value.ToString()

        Dim bus As NhanVienBUS = New NhanVienBUS()
        bus.Update(tmp)
        gvNhanVien_Load()
    End Sub

    Private Sub btnDuoiViec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDuoiViec.Click
        Dim tmp As NhanVienDTO = New NhanVienDTO()
        tmp.HoTen = txtHoTen.Text
        tmp.CMND = txtCMND.Text
        If rdNu.Checked = True Then tmp.GioiTinh = True Else tmp.GioiTinh = False
        tmp.NgaySinh = dtNgaySinh.Value
        tmp.DiaChi = txtDiaChi.Text
        tmp.DienThoai = txtDienThoai.Text
        tmp.MaBC = cmbBangCap.SelectedValue
        tmp.MaCV = cmbChucVu.SelectedValue
        tmp.TinhTrang = False
        tmp.MaNV = gvNhanVien.CurrentRow.Cells(0).Value.ToString()

        Dim bus As NhanVienBUS = New NhanVienBUS()
        bus.Update(tmp)
        gvNhanVien_Load()
    End Sub

    Private Sub gvNhanVien_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvNhanVien.SelectionChanged
        If gvNhanVien.CurrentRow IsNot Nothing Then
            Dim bus As GeneralBUS = New GeneralBUS()
            txtHoTen.Text = gvNhanVien.CurrentRow.Cells(1).Value.ToString()
            txtCMND.Text = gvNhanVien.CurrentRow.Cells(2).Value.ToString()
            If gvNhanVien.CurrentRow.Cells(3).Value = True Then rdNu.Checked = True Else rdNam.Checked = True
            dtNgaySinh.Value = gvNhanVien.CurrentRow.Cells(4).Value.ToString()
            txtDiaChi.Text = gvNhanVien.CurrentRow.Cells(5).Value.ToString()
            txtDienThoai.Text = gvNhanVien.CurrentRow.Cells(6).Value.ToString()
            cmbBangCap.SelectedValue = gvNhanVien.CurrentRow.Cells(7).Value.ToString()
            cmbChucVu.SelectedValue = gvNhanVien.CurrentRow.Cells(8).Value.ToString()
        End If
    End Sub

End Class
